package org.yi.fc.entity;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.jfinal.plugin.activerecord.Model;

public class FRole extends Model<FRole>{

	private static final long serialVersionUID = 1L;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	public static FRole dao = new FRole();
	
	/**
	 * 根据用户id获取该用户创建的所有角色
	 * @param id
	 * @return
	 */
	public List<FRole> getRolesByCreateUserId(int id){
		logger.debug("call getRolesByCreateUserId('{}'),【id={}】",id,id);
		String sql = "select * from f_role where crate_user_id = ?";
		return find(sql, id);
	}
	
	/**
	 * 根据角色的主键数组获取角色列表
	 * @param ids
	 * @return
	 */
	public List<FRole> getRolesByIds(int [] ids){
		Preconditions.checkNotNull(ids,"根据角色的主键数组获取角色列表时，主键数组不能weikong");
		StringBuffer sql = new StringBuffer("select * from f_role where id in (");
		for(int id : ids){
			sql.append(id).append(",");
		}
		sql.setCharAt(sql.length() - 1, ' ');
		sql.append(")");
		
		List<FRole> roles = find(sql.toString());
		return roles;
	}
	
}
